import 'package:flutter/material.dart';

/// 悬浮效果控件
class ComHover extends StatefulWidget {
  final Widget child;
  final Color hoverColor;

  const ComHover({super.key, required this.child, required this.hoverColor});

  @override
  State<ComHover> createState() => _ComHoverState();
}

class _ComHoverState extends State<ComHover> {
  bool _isHovered = false;

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (PointerEvent event) {
        // 鼠标进入时的处理
        setState(() {
          _isHovered = true;
        });
      },
      onExit: (PointerEvent event) {
        // 鼠标离开时的处理
        setState(() {
          _isHovered = false;
        });
      },
      child: Container(
        color: _isHovered ? widget.hoverColor : Colors.transparent,
        child: widget.child,
      ),
    );
  }
}
